# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

# Initial PKGBUILD from AUR.
# Old Maintainer: zebulon <zeb (at)zebulon(dot)org(dot)uk>
# Old Contributor: NovaMoon <novamoon1 (at)gmail(dot)com>
# Old Contributor: Erikas Rudinskas <erikmnkl (at)gmail(dot)com>
# Old Contributor: Marcel Unbehaun <f.rostze.ux at gmail dot com>

pkgname=rtl8814au-dkms-git
_pkgname=8814au
_pkgbase=rtl8814au
pkgver=5.8.5.1.r190.g8d82854
pkgrel=1
pkgdesc='RTL8814AU and RTL8813AU chipset driver with firmware v5.8.5.1.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-wireless')
url='https://github.com/morrownr/8814au'
license=('GPL2')
depends=('dkms' 'bc')
makedepends=('git')
conflicts=("${_pkgbase}")
source=("git+https://github.com/morrownr/$_pkgname.git"
        'dkms.conf'
        'arm.patch')
sha512sums=('SKIP'
            '0b775f43e9c281fc92429a6a13565a36ffe53050a4fe9f3ead7da636ad48808e14958b94e4785fb4d47b4813996421e3f13d4e0245b7eacbd2935b4c8843210a'
            '04c09943d2634104e9caaf92f10ccb95b58f4f9b7f72ba118364363b310cc7ebc3450946475647880593e8c05eac6a730e441a88432c876f94a4e6f29b5e1700')

pkgver() {
  cd $_pkgname

  printf '%s.r%s.g%s' '5.8.5.1' "$(git rev-list --count HEAD)" \
    "$(git rev-parse --short HEAD)"
}

prepare() {
  if [ "$CARCH" = "arm" ] || [ "$CARCH" = "armv6h" ] || \
    [ "$CARCH" = "armv7h" ] || [ "$CARCH" = "aarch64" ]; then
    msg2 "Applying patch for ARM architecture..."
		patch rtl8814au/Makefile -i arm.patch
	fi
}

package() {
  cd $_pkgname

  install -dm 755 "$pkgdir/usr/src/$_pkgbase-$pkgver"

  cp -a * "$pkgdir/usr/src/$_pkgbase-$pkgver"
  cp "$srcdir/dkms.conf" "$pkgdir/usr/src/$_pkgbase-$pkgver"

  # Set name and version
  sed -e "s/@_PKGBASE@/$_pkgbase-dkms/" -e "s/@PKGVER@/$pkgver/" \
    -i "$pkgdir/usr/src/$_pkgbase-$pkgver/dkms.conf"
}

